<template>
  <div style="background: #ffffff">
    <div class="app-container" style="background: #ffffff;  ">
      <!-- <div style="background: #ebeff4">
    <div class="app-container" style="background: #ebeff4;margin:10px; "> -->
      <div style="font-weight: bold;"><a @click="morelist" style="color:#898e99;">HH大客合同列表</a> / 订单合同</div>
      <el-form ref="form2" :model="form2" :rules="rulesht" label-width="110px">
        <el-row :gutter="20" style="margin-top: 10px;" v-loading="loading">
          <el-col :span="24">
            <el-card class="update-log">
              <el-row :gutter="10" class="mb8">
                <el-col :span="4">
                  <h5 style="font-size: 14px; color: #252B3A; font-weight: 700;margin-top: 0px;margin-bottom: 20px;">
                    客户信息</h5>
                </el-col>
                <el-col :span="20">
                  <div align="right">
                    <el-form :inline="true" label-width="68px">


                    </el-form>
                  </div>
                </el-col>

              </el-row>
              <el-row>
                <el-col :span="6">
                  <el-form-item label="合同日期" prop="agrDate">
                    <el-date-picker v-model="form2.agrDate" value-format="yyyy-MM-dd" style="width:90%" type="date" readonly
                      @change="changedate($event)" placeholder="选择日期">
                    </el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="合同编号" prop="agrId">
                    <el-input style="width:90%" v-model="form2.agrId" placeholder="请输入合同编号" clearable disabled />
                  </el-form-item>
                </el-col>

                <el-col :span="6">
                  <el-form-item label="商机来源" prop="agrSjly">
                    <el-select placeholder="商机来源" style="width:90%" v-model="form2.agrSjly" clearable disabled>
                      <el-option v-for="dict in dict.type.ht_sjly" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>

                </el-col>
                <el-col :span="6">
                  <el-form-item label="客户名称" prop="khname">
                    <el-input v-model="form2.khname" clearable placeholder="客户名称" readonly>
                      <i slot="suffix" class="el-icon-document-copy ckh" :data-clipboard-text="form2.khname"
                        style="cursor:pointer ;" @click="copy('.ckh')"></i>
                    </el-input>
                  </el-form-item>

                </el-col>
              </el-row>
              <el-row>
                <el-col :span="6">
                  <el-form-item label="客户打款抬头" prop="agrDktt">
                    <el-input style="width:90%" v-model="form2.agrDktt" clearable placeholder="客户打款抬头" readonly>
                      <i slot="suffix" class="el-icon-camera" style="cursor:pointer ;" @click="copyfd"></i>
                    </el-input>

                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="我方收款抬头" prop="agrSkzh">
                    <el-select style="width:90%" v-model="form2.agrSkzh" clearable placeholder="我方收款抬头" disabled>
                      <el-option v-for="dict in dict.type.ht_skzh" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="关联渠道" prop="gsname">
                    <el-input v-model="form2.gsname" style="width:90%" clearable placeholder="关联渠道" readonly
                      >
                      <i slot="suffix" class="el-icon-document-copy cgsqd" :data-clipboard-text="form2.gsname"
                        style="cursor:pointer ;" @click="copy('.cgsqd')"></i>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="实际渠道" prop="sjname">
                    <el-input v-model="form2.sjname" clearable placeholder="实际渠道"  readonly>
                      <i slot="suffix" class="el-icon-document-copy csjqd" :data-clipboard-text="form2.sjname"
                        style="cursor:pointer ;" @click="copy('.csjqd')"></i>
                    </el-input>
                  </el-form-item>
                </el-col>


              </el-row>
              <el-row>

                <el-col :span="6">
                  <el-form-item label="下单模式" prop="agrXdms">
                    <el-select placeholder="下单模式" style="width:90%" v-model="form2.agrXdms" clearable disabled>
                      <el-option v-for="dict in dict.type.ht_xdms" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="订单类型" prop="agrDdlx">
                    <el-select placeholder="订单类型" style="width:90%" v-model="form2.agrDdlx" clearable disabled>
                      <el-option v-for="dict in dict.type.ht_ddlx" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="订单周期" prop="agrDdzq">
                    <el-select placeholder="订单周期" style="width:90%" v-model="form2.agrDdzq" clearable disabled>
                      <el-option v-for="dict in dict.type.ht_ddzq" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="是否新客" prop="agrSfxk">
                    <el-select placeholder="是否新客" style="width:100%" v-model="form2.agrSfxk" clearable disabled>
                      <el-option v-for="dict in dict.type.sys_yes_no" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                    </el-select>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>

                <el-col :span="24">

                  <el-form-item label="备注" prop="mark">
                    <el-input v-model="form2.mark" type="textarea" placeholder="请输入备注" readonly/>
                  </el-form-item>
                </el-col>

              </el-row>
            </el-card>
          </el-col>
        </el-row>
        <el-row :gutter="20" style="margin-top: 10px;">
          <el-col :span="24">
            <el-card class="update-log">
              <el-tabs v-model="activeName" @tab-click="tbClick">
                <el-tab-pane label="附件管理" name="first">
                  <!-- <el-row >
                    <el-upload ref="upload" :limit="10" :action="upload.url" :headers="upload.headers"
                      :file-list="upload.fileList" :on-progress="handleFileUploadProgress" :on-remove="handleupRemove"
                      :on-success="handleFileSuccess" :auto-upload="true" class="hide-upload-list">
                      <el-button type="primary" plain icon="el-icon-plus" size="mini">关联附件</el-button>

                    </el-upload>
                  </el-row> -->

                  <el-row :gutter="10" class="mb8" style="margin-top: 15px;">
                    <el-col>
                      <el-table :data="bigfilelist" height="300px" border="" v-loading="loading1"
                        :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                        <el-table-column label="附件名称" align="center" prop="fileName" />
                        <el-table-column label="附件大小" align="center" prop="showsize" width="180" />
                        <el-table-column label="创建时间" align="center" prop="fileCreatetime" width="180" />


                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
                          <template slot-scope="scope">
                            <el-button size="mini" type="text" icon="el-icon-download"
                              @click="downloadfile(scope.row)">下载</el-button>


                          </template>
                        </el-table-column>
                      </el-table>
                    </el-col>

                  </el-row>
                </el-tab-pane>

                <!-- <el-tab-pane label="合作伙伴" name="six">
                  <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                      <el-button type="primary" plain icon="el-icon-plus" size="mini"
                        @click="qxinadd">添加合作伙伴</el-button>

                    </el-col>
                  </el-row>
                  <el-table :data="qxList" border :header-cell-style="{ background: '#eef1f6', color: '#606266' }">
                    <el-table-column label="用户昵称" align="center" prop="userName" width="200" />
                    <el-table-column label="用户类型" align="center" prop="userType">
                      <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.userType == '0'">
                          内部业务员
                        </el-tag>
                        <el-tag type="danger" v-if="scope.row.userType == '1'">
                          外部业务员
                        </el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column label="分润比例（%）" align="center" prop="moneyPro">
                      <template slot-scope="scope">
                        <el-input-number :controls="false" :precision="2" v-model="scope.row.moneyPro" :max=100
                          @change="frpro(scope.$index,scope.row.moneyPro)"></el-input-number>
                      </template>
                    </el-table-column>
                    <el-table-column label="分润金额(元)" align="center" prop="moneyNumber">
                      <template slot-scope="scope">
                        <el-input-number :controls="false" :precision="2" v-model="scope.row.moneyNumber"
                          @change="frmoney(scope.$index,scope.row.moneyNumber)"></el-input-number>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
                      <template slot-scope="scope">
                        <el-button type="danger" size="small" @click="delpow(scope.row)" plain>删除</el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                  <el-row style="float: right;margin-top: 40rpx;">
                    <div style="color: #0151ff;float: right;margin-top: 10px;font-weight: bolder;">{{allmoney}}</div>
                    <div style="float: right;margin-top: 6px;">合计：</div>

                  </el-row>
                </el-tab-pane> -->
              </el-tabs>
              <el-row style="margin-top: 20px;">
                <el-col :span="20">1</el-col>
                <el-col :span="4">
                  <div style="float: right;color: #0048ff;margin-top: 3px;"> {{form2.outmoney}}</div>
                  <div style="float: right;"> 分润金额：</div>
                </el-col>

              </el-row>
            </el-card>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 订单选择弹窗测试 -->
    <el-dialog :title="titleord" :visible.sync="openord" width="1300px" append-to-body v-dialogDrag v-if="openord">
      <el-form :model="queryParamsord" ref="queryForm" size="small" :inline="true" v-show="showSearch"
        label-width="68px">

        <el-form-item label="订单编号" prop="orderId">
          <el-input style="width: 200px" v-model="queryParamsord.orderId" placeholder="请输入订单号" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="订单时间">

          <el-date-picker v-model="dateRange[0]" type="date" value-format="yyyy-MM-dd" placeholder="开始时间">
          </el-date-picker>

        </el-form-item>
        <el-form-item label="">
          <span>至</span>
        </el-form-item>
        <el-form-item label="">

          <el-date-picker v-model="dateRange[1]" type="date" value-format="yyyy-MM-dd" placeholder="结束时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button></el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="customerorderListord"
          @selection-change="handleSelectionChange1" border=""
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @row-click="handleClickTableRow"
          ref="fileTable">
          <el-table-column type="selection" width="55" align="center" :selectable="checkSelect" />
          <el-table-column label="订单编号" align="center" prop="orderId" width="160" />

          <el-table-column label="云服务类型名称" align="center" prop="serviceTypeName" />

          <el-table-column label="订单类型" align="center" prop="orderType" width="80">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_order_type" :value="scope.row.orderType" />
            </template>
          </el-table-column>
          <el-table-column label="订单状态" align="center" prop="status" width="80">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.sys_order_state" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column label="订单金额" align="right" prop="officialAmount">
            <template slot-scope="scope">
              {{ toFixed(scope.row.officialAmount) }}
            </template>
          </el-table-column>
          <el-table-column label="实付金额" align="right" prop="amountAfterDiscount">
            <template slot-scope="scope">
              {{ toFixed(scope.row.amountAfterDiscount) }}
            </template>
          </el-table-column>

          <el-table-column label="支付时间" align="center" prop="paymentTime" width="120">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d} {hh}:{mm}') }}</span>
              <!-- <span>{{ convertUTCTimeToLocalTime(scope.row.paymentTime) }}</span> -->
            </template>
          </el-table-column>
          <el-table-column label="返点金额(¥)" align="center" prop="jeFdsj" v-if="false">
            <template slot-scope="scope">
              {{ toFixed(scope.row.jeFdsj) }}
            </template>
          </el-table-column>
          <el-table-column label="客户名称/帐号" align="left" prop="userName" width="120">
            <template slot-scope="scope">
              <el-tooltip placement="top">
                <div slot="content">{{ scope.row.customer }}<br />{{ scope.row.accountName }}</div>
                <div>
                  <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.customer }}
                  </div>
                  <!-- <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
                    {{ scope.row.accountName }}
                  </div> -->
                </div>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column label="关联渠道" align="left" prop="deaname">
            <template slot-scope="scope">
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" :title="scope.row.deaname">
                {{ scope.row.deaname }}</div>
            </template>
          </el-table-column>
          <el-table-column label="关联合同" align="center" prop="flag">

          </el-table-column>
        </el-table>

        <pagination v-show="totalord > 0" :total="totalord" :page.sync="queryParamsord.pageNum"
          :limit.sync="queryParamsord.pageSize" @pagination="getListord" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ImportClick">确 定</el-button>
        <el-button @click="cancelord">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户选择弹窗测试 -->
    <el-dialog :title="titleqx" width="400px" append-to-body :visible.sync="openqx">
      <el-form :model="qxform" ref="qxform" size="small" label-width="108px">
        <el-form-item label="业务员类型">
          <el-radio-group v-model="qxform.userType" @change="radiochange">
            <el-radio label="0">内部业务员</el-radio>
            <el-radio label="1">外部业务员</el-radio>

          </el-radio-group>

        </el-form-item>
        <el-form-item label="选择业务员">
          <el-select v-model="qxform.userId" @change="handleChangeuser" style="width: 90%;" filterable placeholder="业务员"
            clearable>
            <el-option v-for="item in ywyOptions" :key="item.userId" :label="item.nickName"
              :value="item.userId.toString()"></el-option>
          </el-select>
        </el-form-item>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitqx">确 定</el-button>
        <el-button @click="cancelqx">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 选择客户弹窗测试 -->
    <el-dialog :title="titlekh" :visible.sync="openkh" width="1000px" append-to-body>
      <el-form :model="queryParamsKh" ref="queryFormKh" size="small" :inline="true" label-width="68px"
        @submit.native.prevent>
        <el-form-item label="客户名称" prop="customer">
          <el-input v-model="queryParamsKh.customer" placeholder="请输入客户名称" clearable v-on:input="handleKhQuery"
            @keyup.enter.native="handleKhQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleKhQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryKh">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="khList"
          @selection-change="handleSelectionChangeKh" @row-click="handleClickTableRowA" ref="fileTableA">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="客户编号" align="center" prop="customerIdHw" />
          <el-table-column label="客户名称" align="center" prop="customer" />
          <el-table-column label="帐号" align="center" prop="accountName" />
        </el-table>
        <pagination v-show="totalkh > 0" :total="totalkh" :page.sync="queryParamsKh.pageNum"
          :limit.sync="queryParamsKh.pageSize" @pagination="getListKh" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="khClick">确 定</el-button>
        <el-button @click="khcancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 分配渠道弹窗测试 -->
    <el-dialog :title="titleqd" :visible.sync="openqd" width="1000px" append-to-body>
      <el-form :model="queryParamsQd" ref="queryFormQd" size="small" :inline="true" label-width="68px"
        @submit.native.prevent>
        <el-form-item label="渠道名称" prop="deaName">
          <el-input v-model="queryParamsQd.deaName" placeholder="请输入渠道名称" clearable v-on:input="handleQdQuery"
            @keyup.enter.native="handleQdQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQdQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryQd">重置</el-button>
          <el-button type="success" icon="el-icon-add" size="mini" @click="handleAdd" v-if="sjbtshow">添加实际渠道</el-button>
        </el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="dealerList"
          @selection-change="handleSelectionChangeQd" @row-click="handleClickTableRowB" ref="fileTableB">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="渠道编号" align="center" prop="deaId" width="200" />
          <el-table-column label="渠道名称" align="left" prop="deaName" width="300" />
          <el-table-column label="关联时间" align="left" prop="associatedOn" />
          <!-- <el-table-column label="帐号" align="center" prop="deaUser"  /> -->
          <el-table-column label="渠道类型" align="center" prop="accountIn" width="250">
            <template slot-scope="scopes">

              <el-tag v-if="scopes.row.accountIn == 1" type="danger">实际渠道</el-tag>
              <el-tag v-else>华为渠道</el-tag>


            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totalqd > 0" :total="totalqd" :page.sync="queryParamsQd.pageNum"
          :limit.sync="queryParamsQd.pageSize" @pagination="getListDea" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="qdClick" v-if="sjbtshow">确 定</el-button>
        <el-button type="primary" @click="gsqdClick" v-if="gsbtshow">确 定</el-button>
        <el-button @click="cancelqd">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加实际渠道 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" @submit.native.prevent>
        <el-row>
          <el-col :span="12">
            <el-form-item label="渠道编码" prop="deaCode">
              <el-input v-model="form.deaCode" placeholder="渠道编码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="渠道类型" prop="deaType">
              <el-select placeholder="渠道类型" style="width:100%" v-model="deaType" clearable>
                <el-option v-for="dict in dict.type.dea_type" :key="dict.value" :label="dict.label"
                  :value="parseInt(dict.value)" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="渠道名称" prop="deaName">
          <el-input v-model="form.deaName" placeholder="请输入渠道名称" />
        </el-form-item>
        <el-form-item label="经销商ID" prop="deaId" v-if="false">
          <el-input v-model="form.deaId" placeholder="请输入经销商名称" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人" prop="deaPeople">
              <el-input v-model="form.deaPeople" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="deaTel">
              <el-input v-model="form.deaTel" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="邮箱" prop="deaEmail">
              <el-input v-model="form.deaEmail" placeholder="请输入邮箱" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注" prop="deaAddress">
          <el-input v-model="form.deaAddress" type="textarea" placeholder="请输入公司及开票信息" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--详情弹窗-->
    <el-dialog title="订单详情" :visible.sync="openxq" width="85%" append-to-body :class="$style.ElDialog" v-if="true">
      <orderxx :key="deaval.orderId" :oid="deaval.orderId" :opid="deaval.indirectPartnerId"></orderxx>
    </el-dialog>
    <!-- 选择调帐弹窗 -->
    <el-dialog :title="titletz" :visible.sync="opentz" width="1000px" append-to-body v-dialogDrag v-if="opentz">
      <el-form :model="queryParamsTz" ref="queryFormTz" size="small" :inline="true" label-width="68px"
        @submit.native.prevent>
        <el-form-item label="拨款时间">
          <el-date-picker v-model="dateRangetz[0]" type="date" value-format="yyyy-MM-dd" placeholder="开始时间"
            style="width: 130px !important;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <span>至</span>
        </el-form-item>
        <el-form-item label="">
          <el-date-picker v-model="dateRangetz[1]" type="date" value-format="yyyy-MM-dd" placeholder="结束时间"
            style="width: 130px !important;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="mark">
          <el-input v-model="queryParamsTz.mark" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQueryTz">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryTz">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="tzList" border=""
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @selection-change="handleSelectionChangeTz"
          @row-click="handleClickTableRowD" ref="fileTableD">
          <el-table-column type="selection" width="55" align="center" :selectable="checkSelecttz" />
          <el-table-column label="拨款编号" align="center" prop="transId" width="200" />
          <el-table-column label="客户账号ID" align="center" prop="customerId" v-if="false" />
          <!--
          <el-table-column label="身份类型" align="center" width="100">
            <template slot-scope="scope">
              <span slot="reference" v-if="scope.row.deaname != null">
                <div style="float: left; margin-left: 10px;">经销商</div>
              </span>
              <span slot="reference" v-else-if="scope.row.cname != null">
                <div style="float: left; margin-left: 10px;">客户</div>
              </span>
              <span slot="reference" v-else>
                <div style="float: left; margin-left: 10px;color: red;">未识别</div>
              </span>

            </template>
          </el-table-column> -->
          <!-- <el-table-column label="帐号信息" align="center" prop="customerName" width="220" /> -->

          <el-table-column label="渠道名称" align="center">
            <template slot-scope="scope">
              <span slot="reference" v-if="scope.row.deaname != null">

                <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.deaname }}
                </div>
              </span>
              <span slot="reference" v-else-if="scope.row.cname != null">

                <div style="float: left; margin-left: 10px;">{{ scope.row.cname }}</div>
              </span>
              <span slot="reference" v-else>
                <div style="float: left; margin-left: 10px;color: red;">无关联名称</div>
              </span>
            </template>
          </el-table-column>
          <el-table-column label="调账类型" align="center" prop="operationType" width="80">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.tzlx" :value="scope.row.operationType" />
            </template>
          </el-table-column>
          <el-table-column label="客户id" align="center" prop="customerId" width="150" v-if="false" />
          <el-table-column label="调账时间" align="center" prop="operationTime" width="100">
            <template slot-scope="scope">
              <div>{{ parseTime(scope.row.operationTime, "{y}-{m}-{d}") }}</div>
            </template>
          </el-table-column>
          <el-table-column label="调账金额" align="right" prop="amount" width="80" />

          <el-table-column label="关联合同" align="center" prop="flag" width="130">
          </el-table-column>
          <el-table-column label="备注" align="left" prop="mark">
            <template slot-scope="scope">
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" :title="scope.row.mark">
                {{ scope.row.mark }}</div>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totaltz > 0" :page-sizes="[10, 20, 30, 50, 100]" :total="totaltz"
          :page.sync="queryParamsTz.pageNum" :limit.sync="queryParamsTz.pageSize" @pagination="getListTz" />
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="tzClick">确 定</el-button>
        <el-button @click="tzcancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getToken } from "@/utils/auth";
  import { listPayConItem } from "@/api/payment/PayContract";
  //import { listbkitem } from "@/api/BankdetailsMain/bankdetails";
  import { listAdjust, listAdjustAll, listAdjustItem, updateAdjust } from "@/api/AdjustMain/adjust";
  import { listCustomerinfo } from "@/api/CustomerinfoMain/customerinfo";
  import { tblistCustomerorder, listCustomerorder1, ImportCustomerorder, listCustomerorderAll, listOrderItem, getCustomerorder, delCustomerorder, addCustomerorder, updateCustomerorder, insertxq, listCustomerorderItem, selectywy, updateqdc } from "@/api/CustomerorderMain/customerorder";
  import { listDealerAll, addDealersj, } from "@/api/DealerMain/dealer";
  import { listAgreementBig, getoutAgreementBig, delAgreementBig, addAgreementBig, updateAgreementBig, Htcode } from "@/api/AgreementBig/AgreementBig"

  import { getUserProfile, listuser, listJsy, listuser2 } from "@/api/system/user";
  import { done, TimeDate, GetMonA, GetMonB } from "@/api/public";
  import { listAgreementmoney } from "@/api/Agreementmoney/Agreementmoney"
  import { listCost } from "@/api/cost/cost";
  import orderxx from '@/views/Mycomponents/OrderMain/orderxx';
  import ClipboardJS from 'clipboard';

  export default {
    dicts: ["sys_order_type", "sys_order_state", "ht_ddlx", "ht_skzh", "ht_xdms", "sys_yes_no", "ht_sjly", "ht_ddzq", "dea_type", "tzlx", "tz_type", "sys_order_fdbl", 'cost_pay_type', 'cost_type', "ht_skzh", "bank_type", "agreement_power"],
    name: "Agreement",
    components: {
      orderxx,
    },
    data() {
      return {
        testfile:null,
        bigfilelist: [],
        filearray: [],
        upload: {
          // 是否禁用上传
          isUploading: false,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/AgreementBig/AgreementBigfile/uploadfile",
          // 上传的文件列表
          fileList: []

        },
        allmoney: 0,
        //合作相关
        inuser: [],
        outuser: [],

        allfdbl: null,
        btype: null,//判断是否为添加虚拟合同进
        activeName: 'first',
        deaType: null, //实际渠道值 个人 企业
        zfjeshow: "0.00", //订单金额计算
        tzjeshow: "0.00", //调帐金额计算
        zgfdshow: "0.00",  //暂估返点计算
        fkjeshow: "0.00",  //返客金额
        fqjeshow: "0.00",  //返渠金额
        bkjeshow: "0.00",//银行打款金额
        bkdjce: "0.00",//打款差额

        atype: null, //进页面时的类型，1表示添加，2修改

        ys: 0,//跳转过来的页数，用于加去时加载到对应页

        // 遮罩层
        loading: true,
        //关联订单
        loading1: true,
        //关联调帐
        loading3: true,


        //下拉对应参数
        deaOptionsa: [],
        jsyOption: [],//技术员
        BkOptions: [], //拨款人
        ywyOptions: [],//业务员
        XdOptions: [], //拨款人
        sh1Options: [],//审核人 1
        sh2Options: [], //审核人2

        // 费用管理表格数据-----------------
        costList: [],
        queryParamscost: {
          pageNum: 1,
          pageSize: 10,
          costContract: null,
        },

        //渠道客户对应的渠道-查询参数
        queryParamsdea: {
          pageNum: 1,
          pageSize: 9999,
          dtype: 2,
        },

        //订单数据弹窗选择相关-----------------------
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        openxq: false,
        deaval: {
          //分配时，传值的parm
          orderId: null,
          indirectPartnerId: null,
        },

        titleord: "",
        openord: false,
        // 总条数
        totalord: 0,
        dateRange: [],//订单时间过滤
        dateRangetz: [], //调帐时间过滤
        // 查询参数
        queryParamsord: {
          pageNum: 1,
          pageSize: 20,
          orderId: null,
          customer: null,
          customerId: null,
          serviceTypeCode: null,
          sourceType: null,
          status: null,
          orderType: null,
          amountAfterDiscount: null,
          officialAmount: null,
          measureId: null,
          paymentTime: null,
          currency: null,
          contractId: null,
          amountInfo: null,
          orderInfo: null,
          orderLineItems: null,
          userName: null,
          other1: null,
          other2: null,
          other3: null,
          other4: null,
          other5: null,
          ordselid: [],
        },
        customerorderListord: [],//选择订单弹窗数据列表
        //用于保存返点比例到订单表
        ddform: {},


        //合同实体类加载，这边不写会导致mod数据修改时不刷新，因为没有写restform赋值方法所以直接写这里了--------------------
        form2: {
          jeDk: null,
          jeBk: null,
          sfje: null,
          jeFk: null,
          jeFq: null,
          jeFdsj: null,
          jeFd: null,
          jejFdsj: null,
          jejFd: null,
          jeLrsj: null,
          jeLr: null,
          agrId: null,
          agrDate: null,
          deaId: null,
          realDea: null,
          customerId: null,
          customerIdHw: null,
          userId: null,
          ywyName: null,
          jsuserId: null,
          xduserId: null,
          bkuserId: null,

          agrDktt: null,
          agrDdzq: null,
          agrSkzh: null,
          agrSjly: null,
          agrXdms: null,
          agrDdlx: null,
          agrSfxk: null,
          orderIdItem: null, //获取数据显示到数组
          tzIdItem: null,

          gsname: null,//关联渠道
          sjname: null,//实际渠道
          khname: null,//客户员名称

          ordselid: [], //后台接收保存数据
          tzselid: [],
          qxList: [],
          filelist:[],
        },
        //合同信息校验
        rulesht: {
          agrDate: [
            { required: true, message: "合同日期不能为空" },
          ],
          agrSjly: [
            { required: true, message: "商机来源不能为空" },
          ],
          agrDktt: [
            { required: true, message: "打款抬头不能为空" },
          ],
          agrSkzh: [
            { required: true, message: "收款帐号不能为空" },
          ],
          agrXdms: [
            { required: true, message: "下单模式不能为空" },
          ],
          agrDdlx: [
            { required: true, message: "订单类型不能为空" },
          ],
          agrDdzq: [
            { required: true, message: "订单周期不能为空" },
          ],
          agrSfxk: [
            { required: true, message: "是否新客不能为空" },
          ],
          khname: [
            { required: true, message: "客户名称不能为空" },
          ],
          sjname: [
            { required: true, message: "实际渠道不能为空" },
          ],
          gsname: [
            { required: true, message: "关联渠道不能为空" },
          ],
        },
        //查看权限
        queryqx: {
          htId: null,
        },
        qxList: [],
        titleqx: "",
        openqx: false,
        ywyOptions: [],//业务员
        qxform: {
          userId: null,
          moneyPro: null,
          moneyNumber: null,
          userType: null,
        },
        selectuserid: "",
        selectusername: "",
        checklist: [{ value: "A", label: "订单管理" }, { value: "B", label: "拨款管理" }, { value: "C", label: "流程费用" }, { value: "D", label: "银行明细" }],

        //分配客户相关--------------------
        openkh: false,
        titlekh: "",
        khList: [],
        totalkh: 0,
        khid: [],
        khmc: [],
        // 查询参数
        queryParamsKh: {
          pageNum: 1,
          pageSize: 10,
          customer: null,
          verifiedStatus: 2,
        },

        //流程付款数据------------------
        // 付款申请表格数据
        PaymentList: [],
        queryParamsLc: {
          pageNum: 1,
          pageSize: 100,
          htId: null,
        },

        //实际渠道相关------------------
        title: "",
        open: false,
        //渠道添加弹窗时，隐藏显示
        sjbtshow: false,
        gsbtshow: false,
        //分配渠道相关
        openqd: false,
        titleqd: "",
        dealerList: [],
        deid: [],//分配选中的渠道
        dename: [],

        realDea: [], //实际渠道-选择客户时，赋值
        sjname: [], //实际名称-选择客户时，赋值

        qdval: {//分配时，传值的parm
          realDea: null,
          orderId: null,
        },
        totalqd: 0,
        // 查询参数
        queryParamsQd: {
          pageNum: 1,
          pageSize: 10,
          Dtype: 2,
          accountIn: null,
          deaName: null,
        },
        // 实际渠道表单参数
        form: {
        },

        //实际渠道校验
        rules: {
          deaName: [
            { required: true, message: "渠道名称不能为空", trigger: "blur" },
          ],
          deaUser: [
            { required: true, message: "用户名不能为空", trigger: "blur" },
          ],
          deaCode: [
            { required: true, message: "渠道编码不能为空", trigger: "blur" },
          ],
          deaPeople: [
            { required: true, message: "联系人不能为空", trigger: "blur" },
          ],
          // deaPassword: [
          //   { required: true, message: "用户密码不能为空", trigger: "blur" },
          //   {
          //     min: 5,
          //     max: 20,
          //     message: "用户密码长度必须介于 5 和 20 之间",
          //     trigger: "blur",
          //   },
          // ],
          deaEmail: [
            {
              type: "email",
              message: "请输入正确的邮箱地址",
              trigger: ["blur", "change"],
            },
          ],
          deaTel: [
            { required: true, message: "手机号不能为空", trigger: "blur" },
            {
              pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
              message: "请输入正确的手机号码",
              trigger: "blur",
            },
          ],
        },

        //调帐记录相关-------------------------
        //用于保存调账备份和类型
        tzform: {},
        tzListItem: [],//选中后的调帐列表数据
        opentz: false,
        titletz: "",
        tzList: [],
        tzid: [],//分配选中的渠道
        totaltz: 0,
        // 查询参数
        queryParamsTz: {
          pageNum: 1,
          pageSize: 10,
          other1: null,
          tzdselid: [],
        },

        //银行明细查询参数-------------------------
        bkList: [],
        queryParamsBk: {
          pageNum: 1,
          pageSize: 30,
          agrid: null,
        },

        //下一条上一条查询对比
        searchparms: {
        },
        searchhtlist: [],
        searchdateRange: [],
        btntop: false,
        btnnext: false,


      };
    },

    created() {
      //进来时，加载初始数据
      if (this.$route.query.atype != undefined) {
        this.getselList();//获取下拉数据信息
        this.ys = this.$route.query.ys;
        if (this.$route.query.atype == 1) {
          this.getUser();
          this.form2.agrSkzh = "1";

          this.atype = 1;
          this.form2.bkuserId = "492";
          this.loading1 = false;
          this.loading3 = false;

          //这里判断是否从拨款那边进来的，生成合同的方式要变，同时赋值到列表上 2023-06-29添加--生成虚拟合同
          if (this.$route.query.btype == 2) {
            this.btype = 2;
            this.form2.tzIdItem = this.$route.query.tid;
            let oitemid = this.form2.tzIdItem.split(','); //根据iditemid来绑定列表数据显示
            this.queryParamsTz.tzselid = oitemid;
            this.form2.deaId = this.$route.query.did;
            this.form2.gsname = this.$route.query.dname;;

            this.activeName = "second";
          }

          let x = {};
          x.userId = this.$store.state.user.userId;
          x.userName = this.$store.state.user.nickname;
          x.userType = "0";
          x.moneyPro = 100;
          x.moneyNumber = 0;
          this.qxList.push(x);


        }
        else {

          //前面传过来的查询参数，用于上一下，下一页
          if (this.$route.query.searchparms != undefined) {
            this.searchparms = JSON.parse(this.$route.query.searchparms);
            this.searchdateRange = JSON.parse(this.$route.query.searchdateRange);
            this.btntop = true;
            this.btnnext = true;
          }

          this.atype = 2;

          if (this.$route.query.btype == 2) {
            this.btype = 2;
            this.activeName = "second";
          }

          this.queryqx.htId = this.$route.query.aid;
          //设置分润
          listAgreementmoney(this.queryqx).then(response => {
            this.qxList = response.data;
            this.jsallmoney();
          })

          //查看合同
          getoutAgreementBig(this.$route.query.aid).then(response => {

            this.bkjeshow = "0.00";
            //查询合同对应的银行明细 2024-04-29
            let bkje = 0;
            this.queryParamsBk.bId = this.$route.query.aid;
            listbkitem(this.queryParamsBk).then(response => {
              this.bkList = response.rows;
              this.bkList.forEach(element => {
                bkje += Number(element.bSkje);
              });
              this.bkjeshow = bkje.toFixed(2);

            });

            this.form2 = response.data;
            console.log(response.data);
            this.bigfilelist = response.data.filelist;
            this.atype = 2;
          });
        }
      }
      else {
        alert("访问异常");
        this.morelist();
        return;
      }

      this.dateRange[0] = GetMonA(3);
      this.dateRange[1] = GetMonB();
      this.dateRangetz[0] = "2023-01-01";//先暂定1月1
      //this.dateRangetz[0] = GetMonA(3);
      this.dateRangetz[1] = GetMonB();

      listuser().then(response => {
        this.inuser = response.rows;
      });
      listuser2().then(response => {
        this.outuser = response.rows;
      });
      this.loading1 = false;

    },
    methods: {

      downloadfile(row)
      {
        console.log(row.fileUrl);
        var url = row.fileUrl;//"/profile/agreementfile/2024/07/03/1_20240703173512A001.jpg";///profile//2024/07/10/5_20240710140027A002.jpg
        this.$download.resource(url,false)
        // this.download('AgreementBig/AgreementBigfile/importTemplate', {
        // }, `${row.fileName}`)
      },
      //user_template_${new Date().getTime()}.xlsx
      handlefiledelete(index)
      {
        this.bigfilelist.splice(index,1);
      },
      handleupRemove(item) {
        const index = this.upload.fileList.indexOf(item);
        if (index !== -1) {
          this.upload.fileList.splice(index, 1);
        }
        let indexa = 0;
        this.filearray.forEach((element) => {
          if (element == item.response.msg) {
            this.filearray.splice(indexa, 1);
          }
          indexa++;
        });

      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {

        console.log(response);
        if (response.code == "200") {
          this.bigfilelist.push(response.data);
        }
        console.log(this.bigfilelist);

        // if (response.code == "200") {
        //   this.filearray.push(response.msg);
        //   this.upload.fileList.push(file);
        // }
        // else {
        //   this.upload.fileList.push();
        //   this.$modal.msgError(response.msg);
        // }
      },
      frml() {
        this.qxList.forEach((item, index) => {
          this.qxList[index].moneyNumber = (this.form2.jeLr * this.qxList[index].moneyPro / 100).toFixed(2);
          //console.log("a");
        });
        //console.log("b")
        this.jsallmoney();
      },
      frpro(index, pro) {
        var x = 0;
        this.qxList.forEach((item, index) => {
          x = parseFloat(x) + parseFloat(this.qxList[index].moneyPro);
        });
        this.qxList[index].moneyNumber = (this.form2.jeLr * pro / 100).toFixed(2);
        // if (x > 100) {
        //   this.$modal.msgError("分润比例错误");
        //   this.qxList[index].moneyPro = 0;
        //   this.qxList[index].moneyNumber = 0;
        // }
        // else {
        //   this.qxList[index].moneyNumber = (this.form2.jeLr * pro / 100).toFixed(2);


        // }
        this.jsallmoney();

      },
      frmoney(index, money) {
        var x = 0;
        this.qxList.forEach((item, index) => {
          x = parseFloat(x) + parseFloat(this.qxList[index].moneyNumber);
        });
        this.qxList[index].moneyPro = (money * 100 / this.form2.jeLr).toFixed(2);
        // if (x > this.form2.jeLr) {
        //   this.$modal.msgError("分润金额错误");
        //   this.qxList[index].moneyPro = 0;
        //   this.qxList[index].moneyNumber = 0;
        // }
        // else {
        //   this.qxList[index].moneyPro = (money * 100 / this.form2.jeLr).toFixed(2);

        // }
        this.jsallmoney();


      },
      jsallmoney() {
        this.allmoney = 0;
        this.qxList.forEach(item => {
          this.allmoney = Number(this.allmoney) + Number(item.moneyNumber);
          console.log(this.allmoney);
        });
      },
      radiochange(val) {
        if (val == 1) {
          this.ywyOptions = this.outuser;
        }
        else {
          this.ywyOptions = this.inuser;
        }
        this.qxform.userId = null;
      },
      delpow(row) {
        console.log(row);
        const removeIndex = this.qxList.findIndex(item => item.userName == row.userName)
        console.log(removeIndex);
        if (removeIndex !== -1) {
          this.qxList.splice(removeIndex, 1);
          this.jsallmoney();
        }

      },
      handleChangeuser(val) {
        this.selectuserid = val;
        this.selectusername = this.ywyOptions.find(option => option.userId == val).nickName;
        //console.log(this.selectusername);
      },
      submitqx() {
        const num = this.qxList.findIndex((item) => item.userId === this.qxform.userId);
        if (num != -1) {
          this.$modal.msgError("人员已存在")
        }
        else {
          this.qxform.userName = this.selectusername;
          let x = {};
          x.userId = this.qxform.userId;
          x.userName = this.qxform.userName;
          x.userType = this.qxform.userType;
          x.moneyPro = "0";
          x.moneyNumber = "0";
          this.qxList.push(x);
          this.openqx = false;
        }

      },
      cancelqx() {
        this.openqx = false;
      },
      qxinadd() {
        this.titleqx = "添加合作伙伴";
        this.openqx = true;
        this.ywyOptions = this.inuser;
        this.qxform.userId = null;
        this.qxform.userName = null;
        this.qxform.moneyPro = null;
        this.qxform.moneyNumber = null;
        this.qxform.userType = "0";

      },
      qxoutadd() {
        this.titleqx = "添加合作伙伴";
        this.openqx = true;
        this.ywyOptions = this.outuser;
        this.qxform.userId = null;
        this.qxform.userName = null;
        this.qxform.moneyPro = null;
        this.qxform.moneyNumber = null;
        this.qxform.userType = "1";
      },

      //流程费用跳转查看
      handlefind(row) {
        let id = row.paySpnoid;
        let routeData = this.$router.resolve({ path: '/jsgl/paymentpage', query: { id: id } });
        window.open(routeData.href, '_blank');

      },
      //三个标签切换
      tbClick(tab, event) {
        //console.log(tab, event);
      },
      //复制客户名称
      copy(cval) {
        var clipboard = new ClipboardJS(cval)
        clipboard.on('success', e => {
          // console.log('复制成功')
          // 释放内存
          this.$modal.msgSuccess("复制成功");
          clipboard.destroy()
        })
        clipboard.on('error', e => {
          // 不支持复制
          this.$modal.msgWarning("该浏览器不支持自动复制");
          //console.log('该浏览器不支持自动复制')
          // 释放内存
          clipboard.destroy()
        })
      },

      findcost: function (atype, row) {
        var rid = "";
        if (row != null)
          rid = row.costId;
        let routeData = this.$router.resolve({ path: '/jsgl/costs', query: { atype: atype, did: null, aid: rid, } });
        window.open(routeData.href, '_blank');
      },

      //获取当前登录业务员信息
      getUser() {
        getUserProfile().then(response => {
          this.form2.userId = response.data.userId.toString();
          this.form2.ywyName = response.data.nickName
        });
      },
      // 表单重置
      reset() {
        this.form = {

        };
        this.resetForm("form");
      },
      //保留两位，不足补位
      toFixed(num) {
        return (Math.round(num * 100) / 100).toFixed(2);
      },
      /** 查询客户列表 下拉绑定*/
      getselList() {

        //2024-04-29 注销，这个好像没用到现在。包含查询参数和变量定义
        // listDealerAll(this.queryParamsdea).then((response) => {
        //   this.deaOptionsa = response.rows;
        // });

        //绑定技术员
        listJsy().then((response1) => {
          this.jsyOption = response1.rows;
          this.XdOptions = response1.rows;
        });
        //绑定业务员
        listuser(this.queryParamsUser).then(response => {
          this.ywyOptions = response.rows;
          this.BkOptions = response.rows;

          this.sh1Options = response.rows;
          this.sh2Options = response.rows;

          this.loading = false;
        });
      },

      /** 弹窗查询订单列表列表 */
      getListord() {
        //判断表格列是否显示。测试管用
        this.loading = true;
        listCustomerorderAll(this.addDateRange(this.queryParamsord, this.dateRange)).then(response => {
          this.customerorderListord = response.rows;
          this.totalord = response.total;
          this.loading = false;

        });
      },

      plusOrMinus(values) {
        let newValue;
        if (!(/[^0-9.-]/g.test(values))) {
          newValue = values.replace(/[^\-\d.]/g, '').replace(/\-{2,}/g, '-').replace(/\-{2,}/g, '-').replace(/^\./g, '')
            .replace(/\.{2,}/g, '.')
            .replace('.', '$#$')
            .replace(/\./g, '')
            .replace('$#$', '.');
          if (newValue.toString().indexOf('.') > 0 && Number(newValue.toString().split('.')[1].length) > 2) {
            newValue = parseInt(parseFloat(newValue) * 100) / 100;
          }
          if ((newValue.toString().split('-').length - 1) > 1) {
            newValue = parseFloat(newValue) || '';
          }
          if ((newValue.toString().split('-').length) > 1 && newValue.toString().split('-')[0].length > 0) {
            newValue = parseFloat(newValue) || '';
          }
          if (newValue.toString().length > 1 && (newValue.toString().charAt(0) === '0' || (newValue.toString().length > 2 && newValue.toString().charAt(0) === '-' && newValue.toString().charAt(1) === '0' && newValue.toString().charAt(2) !== '.')) && newValue.toString().indexOf('.') < 1) {
            newValue = parseFloat(newValue) || '';
          }
          // 判断整数位最多为9位
          if (newValue.toString().indexOf('.') > 0 && Number(newValue.toString().split('.')[0].length) > 9) {
            newValue = `${newValue.toString().substring(0, 9)}.${newValue.toString().split('.')[1]}`;
          } else if (newValue.toString().indexOf('.') < 0 && Number(newValue.toString().split('.')[0].length) > 9) {
            newValue = newValue.toString().substring(0, 9);
          }
        } else {
          newValue = values.replace(/[^0-9.-]/g, '');
        }
        return newValue;
      },
      // 额外费用校验输入正负数， 保留2位小数 调用公共方法
      RestrictedMoney(values) {
        return this.plusOrMinus(values.toString());
      },
      // 结合change事件对失去焦点进行判断，防止输入一些无效值
      materielExtraCostChange(item, type) {
        // 防止删除为空
        if (!item) {
          item = '0.00';
        }
        // 一些错误金额输入的判断
        if (item.toString().indexOf('.') > 0 && Number(item.toString().split('.')[1].length) < 1) {
          item = item.toString().split('.')[0];
        }
        // 一些错误金额输入的判断
        if (!item || item === '-' || item === '-0') {
          item = '0.00';
          return;
        }
        item = parseFloat(item).toFixed(2);
        if (type == 1)
          this.form2.jeDk = item;
        if (type == 2)
          this.form2.jeBk = item;
        if (type == 3)
          this.form2.jeFk = item;
        if (type == 4)
          this.form2.jeFq = item;
        if (type == 5)
          this.form2.jeFd = item;
        if (type == 6)
          this.form2.jeFdsj = item;
        if (type == 7)
          this.form2.jejFdsj = item;
        if (type == 8)
          this.form2.jejFd = item;
      },
      /** 返回列表 */
      morelist() {
        this.$router.push(
          {
            path: '/htxg/agreementbig2',
            methods: 'post',
            query: {
              ys: this.ys,
            }
          })
      },
      /** 新增按钮操作 */
      adddd() {
        if (this.form2.khname == "" || this.form2.khname == null) {
          this.$modal.msgWarning("请先选择对应客户");
        }
        else {

          this.queryParamsord.ordselid = null;
          this.openord = true;
          this.titleord = "订单选择弹窗";
          // this.queryParamsord.customerId = this.form2.customerIdHw;
          this.resetQuery();
        }
      },
      changedate(val) {
        if (this.atype == 1) {
          //修改时，不变合同号,会导致主键问题
          if (this.btype == 2)
            this.form2.agrId = 'XHWY' + val.split("-").join("") + '-' + done(3, 9);
          else
            this.form2.agrId = 'BHWY' + val.split("-").join("") + '-' + done(3, 9);
        }
      },
      //订单取消
      cancelord() {
        this.openord = false;
        this.reset();
      },
      // 订单弹窗多选框选中数据1
      handleSelectionChange1(selection) {
        this.queryParamsord.ordselid = selection.map(item => item.orderId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 订单搜索按钮操作 */
      handleQuery() {
        this.queryParamsord.pageNum = 1;
        this.queryParamsord.customerId = this.form2.customerId;
        this.getListord();
      },
      /** 订单重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      //计算利润
      clickjs() {
        //必须转成int 才行，否则会计算不正确
        //为空时赋值0
        if (this.form2.jeDk == null || this.form2.jeDk == '')
          this.form2.jeDk = "0.00";
        if (this.form2.jeBk == null || this.form2.jeBk == '')
          this.form2.jeBk = "0.00";
        if (this.form2.jeFd == null || this.form2.jeFd == '')
          this.form2.jeFd = "0.00";
        if (this.form2.jeFdsj == null || this.form2.jeFdsj == '')
          this.form2.jeFdsj = "0.00";
        if (this.form2.jeFk == null || this.form2.jeFk == '')
          this.form2.jeFk = "0.00";
        if (this.form2.jeFq == null || this.form2.jeFq == '')
          this.form2.jeFq = "0.00";
        if (this.form2.jejFdsj == null || this.form2.jejFdsj == '')
          this.form2.jejFdsj = "0.00";
        if (this.form2.jejFd == null || this.form2.jejFd == '')
          this.form2.jejFd = "0.00";

        //实际返点，结合华为
        const a = this.toFixed(Number(this.form2.jeDk) - Number(this.form2.jeBk));
        const b = this.toFixed(Number(a) + Number(this.form2.jeFdsj));

        const c = this.toFixed(Number(b) - Number(this.form2.jeFk));
        const d = this.toFixed(Number(c) - Number(this.form2.jeFq));
        const e = this.toFixed(Number(d) + Number(this.form2.jejFdsj));

        //业务员返点
        const b1 = this.toFixed(Number(a) + Number(this.form2.jeFd));
        const c1 = this.toFixed(Number(b1) - Number(this.form2.jeFk));
        const d1 = this.toFixed(Number(c1) - Number(this.form2.jeFq));
        const e1 = this.toFixed(Number(d1) + Number(this.form2.jejFd));
        // console.log(e);
        // console.log(d1);
        //this.form2.jeLrsj = e;
        this.form2.jeLrsj = "0.00";
        this.form2.jeLr = e1;
        //this.form2 = Object.assign({},this.form2);

      },
      /** 设置价格提交按钮 */
      submitForm2() {
        this.form2.qxList = this.qxList;
        this.form2.filelist = this.bigfilelist;
        // console.log(this.tzListItem);
        // this.tzListItem.forEach(element => {
        //   this.tzform.transId = element.transId;
        //   this.tzform.mark = element.mark;
        //   this.tzform.applx = element.applx;
        //   var a = 1;
        //   if (this.tzform.applx != null) {
        //     a = 2;
        //   }
        //   if (this.tzform.mark != null) {
        //     a = 2;
        //   }
        //   if (a == 2) {
        //     updateAdjust(this.tzform).then(response => {
        //     });
        //   }
        // });

        // //保存返点比例到订单表中
        // this.customerorderListItem.forEach(element => {
        //   if (element.jeFd != null) {
        //     this.ddform.orderId = element.orderId;
        //     this.ddform.jeFd = element.jeFd;
        //     updateCustomerorder(this.ddform).then(response => {
        //     });
        //   }
        // });
        this.$refs["form2"].validate(valid => {
          if (valid) {
            if (this.atype == 2) {
              updateAgreementBig(this.form2).then(response => {
                this.$modal.msgSuccess("修改成功");
                if (this.$store.state.user.userId == 118)
                  this.morelist();
              });
            } else {

              addAgreementBig(this.form2).then(response => {
                this.$modal.msgSuccess("保存成功");
                this.atype = 2;
                if (this.$store.state.user.userId == 118)
                  this.morelist();
              });
            }

          }
        });
        //this.$store.dispatch("htxg/agreementht", this.$route);
      },
      /** 选择客户相关事件 */
      showkh() {
        this.openkh = true;
        this.titlekh = "选择客户";
        this.getListKh();
      },
      khcancel() {
        this.openkh = false;
      },
      /** 搜索按钮操作 */
      handleKhQuery() {
        this.getListKh();
      },
      /**分配客房窗口重置 */
      resetQueryKh() {
        this.resetForm("queryFormKh");
        this.handleKhQuery();
      },
      /** 分配客户多选框选中数据1 客户*/
      handleSelectionChangeKh(selection) {
        this.khid = selection.map(item => item.customerIdHw)
        this.khmc = selection.map(item => item.customer)

        this.deid = selection.map(item => item.deaId), //归属渠道element.realDea;
          this.dename = selection.map(item => item.deaName), //归属名称

          this.realDea = selection.map(item => item.realDea), // realDea;
          this.sjname = selection.map(item => item.realDeaName), //实际名称

          this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 查询分配客户列表 */
      getListKh() {

        // if(this.form2.khname!=null)
        // this.queryParamsKh.customer=this.form2.khname;
        listCustomerinfo(this.queryParamsKh).then(response => {
          this.totalkh = response.total;
          this.khList = response.rows;
        });
      },
      /** 分配客户操作 */
      khClick() {
        if (this.khid.length > 1) {
          this.$modal.msgWarning("只能选择一个客户");
          return;
        }
        this.form2.customerId = this.khid[0];
        this.form2.khname = this.khmc[0];

        this.form2.deaId = this.deid[0];
        this.form2.gsname = this.dename[0];
        //没有实际渠道，取归属渠道
        if (this.realDea == '' || this.realDea == null) {
          this.form2.realDea = this.deid[0];
          this.form2.sjname = this.dename[0];
        }
        else {
          this.form2.realDea = this.realDea[0];
          this.form2.sjname = this.sjname[0];
        }

        this.khcancel();
      },

      /****渠道操作相关 */
      showsjqd(type) {

        if (type == 1) {
          //表示实际渠道
          this.sjbtshow = true;
          this.gsbtshow = false;
          this.titleqd = "分配实际渠道";
          this.queryParamsQd.accountIn = null;
        }
        else {
          //表示归属渠道
          this.sjbtshow = false;
          this.gsbtshow = true;
          this.titleqd = "分配关联渠道";
          this.queryParamsQd.accountIn = 0;
        }

        this.openqd = true;

        this.getListDea();
      },
      /** 查询分配渠道列表 */
      getListDea() {
        this.loading = true;
        listDealerAll(this.queryParamsQd).then((response) => {
          this.dealerList = response.rows;
          this.totalqd = response.total;
          this.loading = false;

        });
      },
      // 分配弹窗多选框选中数据1 渠道
      handleSelectionChangeQd(selection) {
        this.deid = selection.map(item => item.deaId)
        this.dename = selection.map(item => item.deaName)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      cancelqd() {
        this.openqd = false;
        this.reset();
      },
      /** 分配渠道搞操作 */
      qdClick() {
        if (this.deid.length > 1) {
          this.$modal.msgWarning("只能选择一个渠道");

          return;
        }
        this.form2.realDea = this.deid[0];
        this.form2.sjname = this.dename[0];
        this.cancelqd();
      },
      gsqdClick() {
        if (this.deid.length > 1) {
          this.$modal.msgWarning("只能选择一个渠道");
          return;
        }

        this.form2.deaId = this.deid[0];
        this.form2.gsname = this.dename[0];
        this.cancelqd();
      },
      /**分配渠道窗口重置 */
      resetQueryQd() {
        this.resetForm("queryFormQd");
        this.handleQdQuery();
      },
      /** 搜索按钮操作 */
      handleQdQuery() {
        this.getListDea();
      },

      //复制返点金额
      copyfd() {
        this.form2.agrDktt = this.form2.sjname;
      },
      /** 新增实际渠道按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加渠道信息";
        this.deaType = 1;

        const tsj = TimeDate();
        this.form.deaCode = 'QD' + tsj.split("-").join("") + '-' + done(3, 9);

      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      /** 实际渠道提交按钮 */
      submitForm() {
        this.form.deaType = this.deaType;
        this.$refs["form"].validate((valid) => {
          if (valid) {
            addDealersj(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;

            });
          }
        });
      },
      /** 查看订单情况 */
      xqtc(row) {
        this.openxq = true;
        this.deaval.orderId = row.orderId;
        this.deaval.indirectPartnerId = row.indirectPartnerId;
      },
      /** 订单选择列表，判断是否与当前合同编号一致，不可选
  * row：当前行数据
  * index：当前第几位
  */
      checkSelect(row, index) {
        let isChecked = true;
        if (row.flag != null && row.flag != '' && row.flag != this.form2.agrId) { // 判断里面是否存在某个参数
          isChecked = false
        } else {
          isChecked = true
        }
        return isChecked
      },
      handleClickTableRow(row, event, column) {
        if (row.flag != null && row.flag != '' && row.flag != this.form2.agrId) { // 判断里面是否存在某个参数

        } else {
          this.$refs.fileTable.toggleRowSelection(row);
        }

      },
      handleClickTableRowA(row, event, column) {
        this.$refs.fileTableA.toggleRowSelection(row);
      },
      handleClickTableRowB(row, event, column) {
        this.$refs.fileTableB.toggleRowSelection(row);
      },


      /** 选择调帐相关事件 */
      addtz() {
        if (this.form2.gsname == "" || this.form2.gsname == null) {
          this.$modal.msgWarning("请先选择关联渠道");
        }
        else {
          this.queryParamsTz.tzselid = null;
          this.queryParamsTz.other1 = this.form2.deaId;
          this.opentz = true;
          this.titletz = "选择调帐记录";
          this.getListTz();
        }
      },
      /** 查询调帐列表 */
      getListTz() {

        listAdjustAll(this.addDateRange(this.queryParamsTz, this.dateRangetz)).then(response => {
          // listAdjust(this.queryParamsTz).then(response => {
          this.tzList = response.rows;
          this.totaltz = response.total;

        });
      },
      tzcancel() {
        this.opentz = false;
      },
      /** 搜索按钮操作 */
      handleQueryTz() {
        this.getListTz();
      },
      /**分配合同窗口重置 */
      resetQueryTz() {
        this.resetForm("queryFormTz");
        this.handleQueryTz();
      },
      /** 分配调帐多选框选中数据1 */
      handleSelectionChangeTz(selection) {
        this.queryParamsTz.tzselid = selection.map(item => item.transId)

        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      handleClickTableRowD(row, event, column) {
        this.$refs.fileTableD.toggleRowSelection(row);
      },
      checkSelecttz(row, index) {
        let isChecked = true;
        if (row.flag != null && row.flag != '' && row.flag != this.form2.agrId) { // 判断里面是否存在某个参数
          isChecked = false
        } else {
          isChecked = true
        }
        return isChecked
      },
      /** 分配调帐确认操作 */
      tzClick() {
        //判断是否选择了订单
        const eee = this.queryParamsTz.tzselid; //选中的订单

        if (eee.length < 1) {
          this.$modal.msgWarning("请至少选择一条数据");

          return;
        }
        //判断表格列是否显示。测试管用

        this.loading3 = true;

        listAdjustItem(this.queryParamsTz).then(response => {
          if (this.tzListItem.length > 0) {
            response.rows.forEach(el1 => {
              this.tzListItem.push(el1);
            });
          }
          else
            this.tzListItem = response.rows;

          //数组对象去重
          let uniqueDataList = this.tzListItem.filter((item, index, self) => {
            // 返回第一个匹配项的索引，用于判断当前项是否为第一个匹配项
            const firstIndex = self.findIndex((obj) => obj.transId === item.transId);
            // 如果当前项是第一个匹配项，则保留，否则过滤掉
            return index === firstIndex;
          });
          this.tzListItem = uniqueDataList;

          this.loading3 = false;
          this.Tzjx();
        });
        this.tzcancel();
      },
      // 调帐删除行
      handleDeletetz(index, row) {
        this.tzListItem.splice(index, 1);
        this.Tzjx();
      },
      //调帐实体类赋值选中行
      Tzjx() {
        let oid = "";
        let tzje = 0;
        this.tzListItem.forEach(element => {

          oid += element.transId + ",";
          //这里如果是回收的，要减去金额
          if (element.operationType == "SOURCE_OPERATION_BERETRIEVE")
            tzje = tzje - Number(element.amount);
          else
            tzje += Number(element.amount);
        });
        let oiditem = [];
        if (oid.length > 0) {
          oid = oid.substring(0, oid.length - 1);
          oiditem = oid.split(',');
        }
        this.tzjeshow = tzje.toFixed(2);
        this.form2.tzselid = oiditem;

      },
      //跳转到银行明细页面 - 添加 -修改 传类型参数
      findbk: function (atype, row) {
        var rid = "";
        if (row != null)
          rid = row.bId;
        var bids = [];
        bids.push(rid);

      //  let routeData = this.$router.resolve({ path: '/jsgl/bankdetailsht', query: { atype: atype, aid: bids, } });
        //window.open(routeData.href, '_blank');
      },
      //上一条按钮
      topht() {
        listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {

          this.searchhtlist = response.rows;

          let sl = this.searchhtlist.length;

          let i = 0;
          this.searchhtlist.forEach(element => {
            i++;
            if (element.agrId == this.$route.query.aid) {

              if (i <= sl) {
                if (i - 1 > 0) {

                  let tzid = this.searchhtlist[i - 2].agrId;
                  // alert(tzid);
                  window.close();
                  let routeData = this.$router.resolve({
                    path: '/htxg/agreementbight', query: {
                      atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                    }
                  });
                  window.open(routeData.href, '_blank');
                }
                else {
                  let ps = this.searchparms.pageSize; //每页数
                  let pn = this.searchparms.pageNum; //当前页
                  let pys = response.total / ps; //总页数
                  if (pn != 1) {
                    this.searchparms.pageNum = pn - 1;
                    listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {
                      this.searchhtlist = response.rows;
                      // console.log(this.searchhtlist);
                      let sl = this.searchhtlist.length;

                      let tzid = this.searchhtlist[sl - 1].agrId;

                      window.close();
                      let routeData = this.$router.resolve({
                        path: '/htxg/agreementbight', query: {
                          atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                        }
                      });
                      window.open(routeData.href, '_blank');
                    });
                  }
                  else {
                    this.$modal.msgSuccess("未查询到上一条数据！");
                  }

                }
              }


            }
          });
        });

      },
      //下一条按钮
      nextht() {

        listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {

          this.searchhtlist = response.rows;


          let sl = this.searchhtlist.length;
          //  console.log(sl);
          let i = 0;
          this.searchhtlist.forEach(element => {
            i++;
            if (element.agrId == this.$route.query.aid) {
              // console.log(element.agrId);
              if (i < sl) {
                // console.log(i);
                // console.log(this.searchhtlist[i].agrId);
                let tzid = this.searchhtlist[i].agrId;
                window.close();
                let routeData = this.$router.resolve({
                  path: '/htxg/agreementbight', query: {
                    atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                  }
                });
                window.open(routeData.href, '_blank');
              }
              else {
                //这里要判断有没有下一页数据，有的话，查询出来再执行上面的方法
                // console.log(this.searchparms);
                // console.log(response.total);
                let ps = this.searchparms.pageSize; //每页数
                let pn = this.searchparms.pageNum; //当前页
                let pys = response.total / ps; //总页数
                if (pn < pys) {
                  this.searchparms.pageNum = pn + 1;
                  listAgreement(this.addDateRange(this.searchparms, this.searchdateRange)).then(response => {
                    this.searchhtlist = response.rows;
                    // console.log(this.searchhtlist);
                    let sl = this.searchhtlist.length;

                    let tzid = this.searchhtlist[0].agrId;
                    window.close();
                    let routeData = this.$router.resolve({
                      path: '/htxg/agreementbight', query: {
                        atype: 2, did: null, aid: tzid, ys: this.searchparms.pageint, searchparms: JSON.stringify(this.searchparms), searchdateRange: JSON.stringify(this.searchdateRange)
                      }
                    });
                    window.open(routeData.href, '_blank');

                  });
                }
                else {
                  this.$modal.msgSuccess("未查询到下一条数据！");
                }
              }
            }
          });
        });

      },
    },

    };
</script>
<style>
  .el-table th.gutter {
    display: table-cell !important;
    /* 解决表头线未对齐 */
  }

  .jeclass .el-input__inner {
    text-align: right;
  }

  .hide-upload-list .el-upload-list {
    display: none;
  }
</style>
<style lang="scss" module>
  .ElDialog {
    :global .el-dialog__body {
      padding: 1px !important;
    }
  }
</style>
